home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / EventLoop.c < prev    next >
Text File  |  1996-06-22  |  4KB  |  183 lines

  1. /* EventLoop.c */    /*    C14 Calculator */
  2.  
  3. /*-----------*/
  4. /*#include <Types.h>*/
  5. /*#include <Quickdraw.h>*/
  6. /*#include <Controls.h>*/
  7. /*#include <Desk.h>*/
  8. /*#include <Dialogs.h>*/
  9. /*#include <DiskInit.h>*/
  10. /*-----------*/
  11.  
  12. #include <Editions.h>
  13.  
  14. /*-----------*/
  15. #include <EPPC.h>
  16. #include <Events.h>
  17. /*#include <Fonts.h>*/
  18. /*-----------*/
  19.  
  20.  
  21. #include <GestaltEqu.h>
  22.  
  23. /*-----------*/
  24. /*#include <Lists.h>*/
  25. /*#include <Menus.h>*/
  26. #include <OSEvents.h>
  27. /*#include <TextEdit.h>*/
  28. /*#include <ToolUtils.h>*/
  29. /*-----------*/
  30.  
  31. #include <Traps.h>
  32.  
  33. #include <AppleEvents.h>
  34. #include "Globals.h"
  35. #include "Miscellany.h"
  36. #include "AEvent.h"
  37. #include "EventLoop.h"
  38.  
  39. #include "DoScrap.h"
  40. #include "WindowAids.h"
  41. #include "Dispatcher.h"
  42.  
  43. #ifndef __RED__
  44. #include     "ResourceDefs.h"
  45. #endif
  46. //#include    <OSUtils.h>
  47.  
  48. void    EventLoopSeg() {}
  49.  
  50. /*----------*/
  51. #ifndef THINK_C
  52. extern void _DataInit (void);
  53. #endif
  54.  
  55.  
  56. /*----------*/
  57. /*Boolean TrapAvailable    (short            tNumber,
  58.                          TrapType        tType);
  59. Boolean TrapAvailable    (short            tNumber,
  60.                          TrapType        tType)
  61. {
  62.     return (NGetTrapAddress (tNumber, tType)
  63.             != GetTrapAddress (_Unimplemented));
  64. } *//*TrapAvailable*/
  65.  
  66. /*----------*/
  67. void SetStackSize    (long        stackSize);
  68. void SetStackSize    (long        stackSize)
  69. {
  70.     SetApplLimit ((Ptr) ((long) &stackSize - stackSize));
  71. } /*SetStackSize*/
  72.  
  73.  
  74. /*----------*/
  75. static void    GetSysConfig    (void);
  76. static void    GetSysConfig    (void)
  77. {
  78.     OSErr            ignoreError;
  79.     long            tempLong;        /*for Gestalt*/
  80.     SysEnvRec        environs;
  81.  
  82.     sysConfig.hasGestalt = (Gestalt (gestaltVersion, &tempLong) == noErr);
  83.     if (sysConfig.hasGestalt) {
  84.         sysConfig.hasWNE = true;
  85.         ignoreError = Gestalt (gestaltQuickdrawVersion, &tempLong);
  86.         sysConfig.hasColorQD = (tempLong != gestaltOriginalQD);
  87.         sysConfig.hasAppleEvents = (Gestalt (gestaltAppleEventsAttr, &tempLong) == noErr);
  88.         sysConfig.hasEditionMgr = (Gestalt (gestaltEditionMgrAttr, &tempLong) == noErr);
  89.         if (sysConfig.hasEditionMgr) {
  90.             if (!CheckOS (InitEditionPack ())) {
  91.                 sysConfig.hasEditionMgr = false;    /*unable to load Edition Manager package*/
  92.             }
  93.         }
  94.     } else {
  95.         ignoreError = SysEnvirons (curSysEnvVers, &environs);
  96.         if (environs.machineType < 0) {
  97.             sysConfig.hasWNE = false;
  98.         } else {
  99.             sysConfig.hasWNE = true;
  100.         }
  101.         sysConfig.hasColorQD = environs.hasColorQD;
  102.         sysConfig.hasAppleEvents = false;
  103.         sysConfig.hasEditionMgr = false;
  104.     }
  105. } /*GetSysConfig*/
  106. /*----------*/
  107. void DoUpdate    (EventRecord    gTheEvent)
  108. {
  109.     GrafPtr            savePort;
  110.     WindowPtr        saveWindow;
  111.     WindowPtr        whichWindow;
  112.  
  113.     GetPort (&savePort);
  114.     whichWindow = (WindowPtr) gTheEvent.message;
  115.     SetPort (whichWindow);
  116.     saveWindow = curWindow;
  117.     SetInfo (whichWindow);
  118.     BeginUpdate (whichWindow);
  119.         EraseRect (&(whichWindow->portRect));
  120.         DrawControls (whichWindow);
  121.         UpdateContent ();            /*    Dispatcher.c    */
  122.     EndUpdate (whichWindow);
  123.     SetInfo (saveWindow);    
  124.     SetPort (savePort);
  125. } /*DoUpdate*/
  126.  
  127.  
  128. /*----------*/
  129. void DoActivate        (EventRecord    gTheEvent)/*(WindowPtr    whichWindow)*/
  130. {
  131.     Boolean            activate;
  132.     WindowPtr        whichWindow;
  133.  
  134.     whichWindow = (WindowPtr) /*curEvent*/gTheEvent.message;
  135.     SetPort (whichWindow);
  136.     SetInfo (whichWindow);
  137.     
  138.     activate = ((/*curEvent*/gTheEvent.modifiers & activeFlag) != 0);
  139.     if (activate) {
  140.         if ((cur->text) != NULL) {
  141.             TEActivate (cur->text);
  142.         }
  143.         ReadDeskScrap ();
  144.     }
  145.     
  146.     HiliteScroll (cur->vScroll, activate);
  147.     /*HiliteScroll (cur->hScroll, activate);*/
  148.  
  149.     ActivateContent (activate);
  150.  
  151.     if (!activate) {
  152.         WriteDeskScrap ();
  153.         if (cur->text != NULL) {
  154.             TEDeactivate (cur->text);
  155.         }
  156.         SetInfo (NULL);
  157.     }
  158. } /*DoActivate*/
  159.  
  160. void DoGetSysConfig(void)
  161. {
  162.     
  163. #if defined(applec) /* MPW C */
  164.     UnloadSeg ((Ptr) _DataInit);
  165. #endif /* MPW C */
  166.     
  167.     GetSysConfig ();    
  168.     if (sysConfig.hasAppleEvents) {
  169.         InitializeAE ();
  170.     }
  171. }
  172.  
  173. void    DoSetStackSize(void)
  174. {
  175.  
  176. #if defined(applec) /* MPW C */
  177.     UnloadSeg ((Ptr) _DataInit);
  178. #endif /* MPW C */
  179.  
  180.     
  181.     /*SetStackSize (15000);*/
  182.     SetStackSize (16000);
  183. }